package test.util.hutool

import cn.hutool.core.convert.Convert
import cn.hutool.crypto.SecureUtil
import org.junit.jupiter.api.Test
import java.io.UnsupportedEncodingException
import java.net.URLDecoder
import java.net.URLEncoder


class HutoolTest {

    val KEY = "8b7cff60c3c454a0"

    @Test
    fun `test`() {
        val f1: String = Convert.numberToChinese(10889.72356, false)
        println(f1)
        val f2: String = Convert.numberToChinese(10889.72356, true)
        println(f2)

        val urlParamTicket = "wX8%2BQay%2FcNbBhEuJvDSuWh5x57eOkQ0HLUSISKAXB6SLuDnRUYWQULGOVxT4kSXm4BRbcfvHMkmzlqPAnPcVrw%3D%3D"
        try {
            val aes = SecureUtil.aes(KEY.toByteArray())
            // 解码 ticket (根据实际情况, 如传入已解码, 无须执行此操作)
            val decode: String = URLDecoder.decode(urlParamTicket, "UTF-8")
            // 加密
            val encrypt = aes.encryptBase64(decode)
            // 编码
            val ticket: String = URLEncoder.encode(encrypt, "UTF-8")
            // 携带ticket 请求获取token接口
            // GET https://gj.hqhuitong.com/api/decodeTicket?ticket=xxxx
            println("url 中的 ticket = $urlParamTicket")
            println("原始 ticket 通过 decode 后=$decode")
            println("加密后 = $encrypt")
            println("我要的是这个编码后 = $ticket")
            // 解密校验
//            val decrypt: String = decrypt(encrypt)
//            println("解密后:$decrypt")
        } catch (e: UnsupportedEncodingException) {
            e.printStackTrace()
        }
    }
}